<!DOCTYPE html>
<script>
    if (window.internals) {
        internals.settings.setViewportEnabled(true);
        internals.settings.setViewportMetaEnabled(true);
    }
</script>
<meta name="viewport" content="width=160">
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="resources/currentSrcHelper.js"></script>
<body>
<script>
  async_test(t => {
    let image = new Image();
    image.id = "simple";
    image.sizes = "(max-width: 300px) 100vw, 800px";
    image.srcset = "../../hidpi/resources/image-set-1x.png?3453459 400w, ../../hidpi/resources/image-set-2x.png?3453459 800w";
    document.body.appendChild(image);

    window.onload = t.step_func_done(() => {
      assert_equals(document.getElementById("simple").currentSrc.indexOf("file://"), 0);
      assert_equals(document.getElementById("simple").clientWidth, 160);
      assert_equals(currentSrcFileNameNoParams("simple"), "image-set-1x.png");
      if (window.internals) {
        assert_true(internals.isLoadingFromMemoryCache("../../hidpi/resources/image-set-1x.png?3453459"));
        assert_false(internals.isLoadingFromMemoryCache("../../hidpi/resources/image-set-2x.png?3453459"));
      }
    });
  }, "Test srcset and sizes with a meta viewport");
</script>
